﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Smart.Hotfix
{
    public class Component/* : System.IDisposable*/
    {
        static long ms_guid = 10000L;
        public long InstanceId { get; private set; }
        public bool Disposed { get; protected set; }
        public bool IsFromPool { get; set; }
        public virtual bool Cached => false;

        public ComponentView View { get; set; }

        protected Component()
        {
            InstanceId = ++ms_guid;
        }

        public virtual void Dispose()
        {
            if (Disposed)
            {
                return;
            }
            Disposed = true;
            View = null;
            Entry.Instance.EventSystem.Destroy(this);
            Entry.Instance.EventSystem.Remove(InstanceId);
            InstanceId = 0;
            if(IsFromPool)
            {
                Entry.Instance.ObjectPool.Put(this);
            }
        }
    }
}